package com.nexgo.payment.trans.setting;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;

import com.nexgo.payment.R;
import com.nexgo.payment.constrant.PreferencesConstants;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.setting.merchant.SetupMerchantActivity;
import com.nexgo.payment.trans.setting.network.SetupNetworkActivity;
import com.nexgo.payment.trans.setting.othersfunc.OtherParamActivity;
import com.nexgo.payment.trans.setting.password.SetupPasswordActivity;
import com.nexgo.payment.trans.setting.resetgps.ResetGPSActivity;
import com.nexgo.payment.trans.setting.signature.SetupSignatureActivity;
import com.nexgo.payment.trans.setting.sysparam.SetupSystemActivity;
import com.nexgo.payment.trans.setting.terminalkey.KeyManageActivity;
import com.nexgo.payment.trans.setting.transmanage.TransSwitchActivity;
import com.nexgo.payment.ui.ListMenuActivity;
import com.nexgo.payment.util.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 应用参数设置
 */
public class SystemSettingsActivity extends ListMenuActivity {
    private List<Integer> mItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected String getActivityTitle() {
        return getString(R.string.app_parameter_settings);
    }

    @Override
    protected void onItemClick(int position) {
        if (UIUtils.isDoubleClick()) {
            return;
        }
        int item = mItemList.get(position);
        switch (item) {
            case R.string.merchant_management_settings:
                startActivity(SetupMerchantActivity.newInstance(this));
                break;
            case R.string.trans_management_settings:
                startActivity(TransSwitchActivity.newInstance(this));
                break;
            case R.string.system_parameter_settings:
                startActivity(SetupSystemActivity.newInstance(this));
                break;
            case R.string.network_parameter_settings:
                startActivity(SetupNetworkActivity.newInstance(this));
                break;
            case R.string.terminal_key_management_settings:
                startActivity(KeyManageActivity.newInstance(this));
                break;
            case R.string.password_management_settings:
                startActivity(SetupPasswordActivity.newInstance(this));
                break;
            case R.string.other_function_settings:
                startActivity(OtherParamActivity.newInstance(this));
                break;
            case R.string.electronic_signature_settings:
                startActivity(SetupSignatureActivity.newInstance(this));
                break;
            case R.string.reset_gps:
                Repository.getInstance().setParamValue(PreferencesConstants.RESETGPSCKV,"12345678");
                Repository.getInstance().setParamValue(PreferencesConstants.RESETGPSRANDOM,"12345678");
                startActivity(ResetGPSActivity.newInstance(this));
                break;
            /*case R.string.reset_base_location:
                intent2Activity(ResetBaseActivity.class);
                break;*/
            case R.string.sys_settings:
                startActivity(new Intent(Settings.ACTION_SETTINGS));
                break;
            default:
                break;
        }
    }

    void initView() {
        mItemList = new ArrayList<>();
        mItemList.add(R.string.merchant_management_settings);
        mItemList.add(R.string.trans_management_settings);
        mItemList.add(R.string.system_parameter_settings);
        mItemList.add(R.string.network_parameter_settings);
        mItemList.add(R.string.terminal_key_management_settings);
        mItemList.add(R.string.password_management_settings);
        mItemList.add(R.string.other_function_settings);
        mItemList.add(R.string.electronic_signature_settings);
        mItemList.add(R.string.reset_gps);
//        mItemList.add(R.string.reset_base_location);
        mItemList.add(R.string.sys_settings);
        for (Integer i : mItemList) {
            addItem(i);
        }
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, SystemSettingsActivity.class);
    }
}
